import request from "@/utils/request";
import { ProductSpecOptionForm } from "@/api/biz/product-spec-option";

const PRODUCTSPEC_BASE_URL = "/api/v1/productSpecs";

const ProductSpecAPI = {
  /** 获取菜品规格分页数据 */
  getPage(queryParams?: ProductSpecPageQuery) {
    return request<any, PageResult<ProductSpecPageVO[]>>({
      url: `${PRODUCTSPEC_BASE_URL}/page`,
      method: "get",
      params: queryParams,
    });
  },
  /**
   * 获取菜品规格表单数据
   *
   * @param id 菜品规格ID
   * @returns 菜品规格表单数据
   */
  getFormData(id: number) {
    return request<any, ProductSpecForm>({
      url: `${PRODUCTSPEC_BASE_URL}/${id}/form`,
      method: "get",
    });
  },

  /** 添加菜品规格*/
  add(data: ProductSpecForm) {
    return request({
      url: `${PRODUCTSPEC_BASE_URL}`,
      method: "post",
      data: data,
    });
  },

  /**
   * 更新菜品规格
   *
   * @param id 菜品规格ID
   * @param data 菜品规格表单数据
   */
  update(id: number, data: ProductSpecForm) {
    return request({
      url: `${PRODUCTSPEC_BASE_URL}/${id}`,
      method: "put",
      data: data,
    });
  },

  /**
   * 批量删除菜品规格，多个以英文逗号(,)分割
   *
   * @param ids 菜品规格ID字符串，多个以英文逗号(,)分割
   */
  deleteByIds(ids: string) {
    return request({
      url: `${PRODUCTSPEC_BASE_URL}/${ids}`,
      method: "delete",
    });
  },
};

export default ProductSpecAPI;

/** 菜品规格分页查询参数 */
export interface ProductSpecPageQuery extends PageQuery {}

/** 菜品规格表单对象 */
export interface ProductSpecForm {
  id?: number;
  productId?: number;
  /** 规格名称(如:辣度) */
  name?: string;
  /** 是否必选 */
  isRequired?: number;
  sort?: number;
  /** 规格选项列表 */
  specOptions?: ProductSpecOptionForm[];
}

/** 菜品规格分页对象 */
export interface ProductSpecPageVO {
  id?: number;
  productId?: number;
  /** 规格名称(如:辣度) */
  name?: string;
  /** 是否必选 */
  isRequired?: number;
  sort?: number;
}
